from typing import List

from sqlalchemy.orm import Session

from app.models import PersonalizedWordLibrary
from app.schemas.personalized_word_library import PersonalizedWordLibraryCreate, PersonalizedWordLibraryUpdate
from app.crud.base import CRUDBase

# 创建 PersonalizedWordLibrary 的 CRUD 对象
class CRUDPersonalizedWordLibrary(CRUDBase[PersonalizedWordLibrary, PersonalizedWordLibraryCreate, PersonalizedWordLibraryUpdate]):
    def get_unique_categories(self, db: Session) -> List[str]:
        """
        获取不重复的分类名称列表。
        """
        result = db.query(PersonalizedWordLibrary.category_name).distinct().all()
        return [category[0] for category in result]

# 实例化 CRUD 对象，以便在路由（route）中使用
personalized_word_library = CRUDPersonalizedWordLibrary(PersonalizedWordLibrary)
